package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:33
 */
public class E7 {//数组旋转找到最小的点
    public static void main(String[] args) {
        int arr[] = {1,3,5};
        System.out.println(new E7().minArray(arr));
    }

    public int minArray(int[] numbers){
        int l = 0;
        int r = 0;
        int mid = 0;
        //之后进行循环判断
        while (l < r){
            mid = (l+r)/2;
            if (numbers[l] > numbers[r]){
                l = mid;
            }else if (numbers[mid] == numbers[r]){
                r--;
            }else {
                r = mid;
            }
        }
        return numbers[r];
    }

//    public int minArray(int[] numbers) {
//        int l = 0;
//        int r = numbers.length-1;
//        int mid = 0;
//        while (l < r){//重合就出去
//            mid = (l+r)/2;
//            if (numbers[mid] > numbers[r]){
//                l = mid+1;
//            }else if (numbers[mid] == numbers[r]){
//                r -=1;
//            }else {
//                //number[r]>number[mid]因为是旋转数组所以此时mid 到 right一定连续
//                r= mid;
//            }
//        }
//        return numbers[r];
//    }
}
